package UnionFind;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import org.junit.Test;

import BasicTypes.Constants;

public class QuickUnionTest {

	@Test
	public void testQuickUnion() {
		QuickUnion qu = new QuickUnion(Constants.SIZE * Constants.SIZE, 0);
		//qu.print();
		String dir = "/Users/crazymooner/Documents/Cornell courses/Architecture of Large Scale database/hadoop Input/";
		try {
			
			  FileInputStream fstream = new FileInputStream(dir + "ptest1.txt");
			  // Get the object of DataInputStream
			  DataInputStream in = new DataInputStream(fstream);
			  BufferedReader br = new BufferedReader(new InputStreamReader(in));
			  String strLine;
			  //Read File Line By Line
			  while ((strLine = br.readLine()) != null)   {
				  strLine += " ";
				  StringTokenizer st = new StringTokenizer(strLine);
				  int p = Integer.parseInt(st.nextToken());
				  int q = Integer.parseInt(st.nextToken());
				  qu.unite(p, q);
			  }
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		qu.print();
	}

}
